//
//  IconPickerViewController.swift
//  Checklists
//
//  Created by JokerAtBaoFeng on 16/3/11.
//  Copyright © 2016年 baofeng. All rights reserved.
//

import UIKit

protocol IconPickerViewControllerDelegate: class {
    func iconPicker(picker: IconPickerViewController, didPickIcon iconName: String)
}

class IconPickerViewController: UITableViewController {
    weak var delegate: IconPickerViewControllerDelegate?
    
    let icons = [ "No Icon",
        "Appointments", "Birthdays", "Chores", "Drinks", "Folder", "Groceries","Inbox", "Photos", "Trips"]
    
    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return icons.count
    }
    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("IconCell")
        let iconName = icons[indexPath.row]
        cell?.textLabel?.text = iconName
        cell?.imageView?.image = UIImage(named: iconName)
        
        return cell!
    }
    override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        if let delegate = delegate {
            delegate.iconPicker(self, didPickIcon: icons[indexPath.row])
        }
    }
}
